<template>
<div class="edituser-main">
    <el-card>
        <div slot="header">新增用户</div>
        <div>
            <el-form ref="user" :model="user" label-width="80px">
                <el-row :gutter="10">
                    <el-col :span="8">
                        <el-form-item label="用户名">
                            <el-input v-model="user.name" placeholder="请输入用户名"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="昵称">
                            <el-input v-model="user.nickname" placeholder="请输入用户名"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="收货电话" prop="phone">
                            <el-input v-model="user.phone" placeholder="请输入收货人电话" maxlength="11" minlength="11" show-word-limit></el-input>
                        </el-form-item>
                  </el-col>
                </el-row>
                 <el-row :gutter="10">
                    <el-col :span="8">
                        <el-form-item label="邮箱">
                            <el-input v-model="user.email" placeholder="请输入邮箱"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="性别">
                            <el-switch v-model="user.sex" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="收货电话" prop="phone">
                            <el-input v-model="user.phone" placeholder="请输入收货人电话" maxlength="11" minlength="11" show-word-limit></el-input>
                        </el-form-item>
                  </el-col>
                </el-row>
               
                <el-row :gutter="10">
                    <el-col :span="8" :offset="6">
                        <el-button type="primary" @click="resetUser">重 置</el-button>
                    </el-col>
                    <el-col :span="8">
                        <el-button type="primary" @click="submitUser">提 交</el-button>
                    </el-col>
                </el-row>

            </el-form>
        </div>
    </el-card>
</div>
</template>

<script>
export default {
    components: {

    },
    data() {
        return {
            user: {},
            id: ''

        };
    },
    computed: {

    },
    created() {
        if (this.$route.query.id) {
            this.id = this.$route.query.id
        }

    },
    mounted() {

    },
    methods: {
        resetUser() {
            this.user = {
                icon: ''
            }

        },
        submitUser() {
            console.log(this.advertise);
            this.$confirm('确认提交吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                if (this.user.id) {

                    updateAds(this.user).then(res => {
                        if (res.success) {
                            this.$message.success('编辑成功了')
                            this.$router.push({
                                name: "userList"
                            })
                        } else {
                            this.$message.error('编辑失败了')
                        }
                    })

                } else {
                    addAds(this.user).then(res => {
                        // console.log(res);
                        if (res.success) {
                            this.$message.success('新增成功了')
                            this.$router.push({
                                name: "userList"
                            })
                        } else {
                            this.$message.error('新增失败了')

                        }
                    })
                }
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消提交'
                });
            });

        }

    },
};
</script>

<style scoped lang="scss">

</style>
